package server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;

import javax.swing.SwingUtilities;

public class TCPDesktopServer implements Runnable {

	public static final int SERVERPORT = 12345;

	public void run() {

		try {

			// System.out.println("S: Connecting...");

			ServerSocket serverSocket = new ServerSocket(SERVERPORT);

			while (true) {

				Socket client = serverSocket.accept();

				// System.out.println("S: Receiving...");

				try {
					BufferedReader in = new BufferedReader(
							new InputStreamReader(client.getInputStream()));

					String str = in.readLine();

					System.out.println("Server: Erhaltene Nachricht: '" + str
							+ "'");
				} catch (Exception e) {

					System.out.println("S: Error");

					e.printStackTrace();

				} finally {
					client.close();
					// System.out.println("S: Done.");
				}
			}

		} catch (Exception e) {

			System.out.println("S: Error");

			e.printStackTrace();
		}
	}

	// public static void main (String a[]) {
	//
	// Thread desktopServerThread = new Thread(new TCPDesktopServer());
	//
	// desktopServerThread.start();
	//
	// }
}
